//
//  VedioDrawer.m
//  CarHome
//
//  Created by 蒋寒霄 on 14-9-25.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "VedioDrawer.h"

@implementation VedioDrawer

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self creatView];
    }
    return self;
}

#pragma mark -
#pragma mark creatView

- (void)creatView
{
    // 背景透明BUTTON
    self.background_Button = [UIButton buttonWithType:UIButtonTypeCustom];
    [_background_Button setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [_background_Button setBackgroundColor:[UIColor clearColor]];
    [self addSubview:_background_Button];
    // 功能选择底层View
    UIView *BackTouch_View = [[UIView alloc] initWithFrame:CGRectMake(210, 64, 100, 290)];
    BackTouch_View.layer.cornerRadius = 5.0;
    BackTouch_View.clipsToBounds = YES;
    BackTouch_View.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.95];
    //button title
    NSArray *array = [[NSArray alloc] initWithObjects:@"  全部", @"  原创", @"  试车", @"  花边", @"  事件", @"  新车", @"  广告", @"  技术", nil];
    NSArray *arrImageName = [[NSArray alloc] initWithObjects:@"Rec_AllButton.png", @"Rec_YuanChuangButton.png", @"Rec_TryButton.png", @"Rec_FlowerButton.png", @"Rec_EventButton.png", @"Rec_NewCarButton.png", @"Rec_ADButton.png", @"Rec_TeconologyButton.png", nil];
    //放置功能选择button
    for (int i = 0; i < 8; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setFrame:CGRectMake(0, (30 + 5) * i + 5, BackTouch_View.frame.size.width, 30)];
        [button setTag:1000 + i];
        [button setTitle:[array objectAtIndex:i] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:[arrImageName objectAtIndex:i]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -3, 0, 3);
        [BackTouch_View addSubview:button];
    }
    
    [_background_Button addSubview:BackTouch_View];
    [BackTouch_View release];
    [arrImageName release];
}

- (void)buttonAction:(id)sender
{
    UIButton * button = (UIButton *)sender;
    int num = 0;
    if (button.tag == 1001) {
        num = 8;
    }
    if (button.tag == 1002) {
        num = 2;
    }
    if (button.tag == 1003) {
        num = 4;
    }
    if (button.tag == 1004) {
        num = 7;
    }
    if (button.tag == 1005) {
        num = 1;
    }
    if (button.tag == 1006) {
        num = 3;
    }
    if (button.tag == 1007) {
        num = 5;
    }
    NSString *videoURL = [NSString stringWithFormat:@"http://app.api.autohome.com.cn/autov4.2/news/videos-a2-pm1-v4.2.0-vt%d-p1-s30.html", num];
    self.block(videoURL);
}

#pragma mark -
#pragma mark 1.block的set方法
- (void)setVedioDrawerBlock:(VedioDrawerBlock)block
{
    self.block = block;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
